<template>
    <div class="dialog">
        <el-dialog :title="dialog.title" :visible.sync="dialog.show" :close-on-click-modal='false' :close-on-press-escape='false'
            :modal-append-to-body="false">
            <div class="form">
                <el-form ref="form" :model="formData" :rules="form_rules" label-width="120px" 
                    style="margin:10px;width:auto">
                    <el-form-item label="医生电话" prop="SoPhone">
                        <el-input type="content" v-model="formData.SoPhone"></el-input>
                    </el-form-item>
                    <el-form-item label="医生姓名" prop="SoName">
                        <el-input type="content" v-model="formData.SoName"></el-input>
                    </el-form-item>
                    <el-form-item label="医生年龄" prop="SoAge">
                        <el-input type="content" v-model="formData.SoAge"></el-input>
                    </el-form-item>
                    <el-form-item label="医生职称" prop="Sojian">
                        <el-input type="content" v-model="formData.Sojian"></el-input>
                    </el-form-item>
                    <el-form-item label="医生照片" prop="picture">
                        <el-input type="content" v-model="formData.picture"></el-input>
                    </el-form-item>
                    <el-form-item class="text_right">
                        <el-button @click="dialog.show=false">取消</el-button>
                        <el-button type="primary" @click="onSubmit('form')">提交</el-button>
                    </el-form-item>
                </el-form>

            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                form_rules: {
                    SoPhone: [
                        { required: true, message: '评论内容不能为空', trigger: 'blur' }
                    ],
                    SoName: [
                        { required: true, message: '评论时间不能为空', trigger: 'blur' }
                    ],
                    SoAge: [
                        { required: true, message: '用户id不能为空', trigger: 'blur' }
                    ],
                    Sojian: [
                        { required: true, message: '用户id不能为空', trigger: 'blur' }
                    ],
                    picture: [
                        { required: true, message: '用户id不能为空', trigger: 'blur' }
                    ]
                }
            }
        },
        props: {
            dialog: Object,
            formData: Object
        },
        mounted(){
             
        },
        methods: {

            onSubmit(form) {

                this.$refs[form].validate(valid => {
                    if (valid) { 
                        const url=this.dialog.option=="add" ? "add" : "edit";
                         this.axios({
                             method: 'post',
                             url: `http://127.0.0.1:3000/api/postdoctor/${url}`,
                            data: {
                                Sid:this.formData.Sid,
                                SoPhone:this.formData.SoPhone,
                                SoName:this.formData.SoName,
                                SoAge:this.formData.SoAge,
                                Sojian:this.formData.Sojian,
                                picture:this.formData.picture,
                            }
                        })
                            .then(res => {
                                this.$message({
                                    message: '成功',
                                    type: 'success',
                                })
                                this.dialog.show = false;
                                console.log(this.formData);
                                this.$router.go(0);
                            })
                            .catch(err =>{
                                console.log(err)
                            })

                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>